package avicit.bdp.dcs.plugin.odps;

import avicit.bdp.dcs.plugin.BaseDataxParam;
import avicit.bdp.dcs.plugin.DataxConstants;
import avicit.bdp.dcs.plugin.DataxJsonInterface;
import avicit.bdp.dcs.plugin.odps.param.OdpsDataxParam;

import java.util.HashMap;
import java.util.Map;

/**
 * @金航数码科技有限责任公司
 * @作者：liyb
 * @邮箱：liyb@avic-digital.com
 * @创建时间： 2024-05-22 11:39
 * @类说明：
 * @修改记录：
 */
public class OdpsDataxJson implements DataxJsonInterface {

    /**
     * 获取Reader插件名称
     * @return
     */
    @Override
    public String getReaderName() {
        return DataxConstants.ODPS_READER;
    }

    /**
     * 获取Writer插件名称
     * @return
     */
    @Override
    public String getWriterName() {
        return DataxConstants.ODPS_WRITER;
    }

    @Override
    public Map<String, Object> buildReader(BaseDataxParam param) {
        OdpsDataxParam dataxParam = (OdpsDataxParam) param;

        // 构建
        Map<String, Object> readerObj = new HashMap<>(4);
        readerObj.put(DataxConstants.NAME, getReaderName());
        Map<String, Object> parameterObj = new HashMap<>(16);
        parameterObj.put(DataxConstants.ODPS_ACCESSID, dataxParam.getAccessId());
        parameterObj.put(DataxConstants.ODPS_ACCESSKEY, dataxParam.getAccessKey());
        parameterObj.put(DataxConstants.ODPS_PROJECT, dataxParam.getProject());
        parameterObj.put(DataxConstants.ODPS_TABLE, dataxParam.getTable());
        parameterObj.put(DataxConstants.ODPS_PARTITION, dataxParam.getPartition());
        parameterObj.put(DataxConstants.ODPS_COLUMN, dataxParam.getColumnList());
        parameterObj.put(DataxConstants.ODPS_PACKAGE_AUTHORIZED_PROJECT, dataxParam.getPackageAuthorizedProject());
        parameterObj.put(DataxConstants.ODPS_SPLIT_MODE, dataxParam.getSplitMode());
        parameterObj.put(DataxConstants.ODPS_SERVER, dataxParam.getOdpsServer());

        readerObj.put(DataxConstants.PARAMETER, parameterObj);
        return readerObj;
    }

    @Override
    public Map<String, Object> buildWriter(BaseDataxParam param) {
        OdpsDataxParam dataxParam = (OdpsDataxParam) param;

        Map<String, Object> writerObj = new HashMap<>(4);
        writerObj.put(DataxConstants.NAME, getWriterName());
        Map<String, Object> parameterObj = new HashMap<>(16);

        parameterObj.put(DataxConstants.ODPS_PROJECT, dataxParam.getProject());
        parameterObj.put(DataxConstants.ODPS_TABLE, dataxParam.getTable());
        parameterObj.put(DataxConstants.ODPS_PARTITION, dataxParam.getWriterPartition());
        parameterObj.put(DataxConstants.ODPS_COLUMN, dataxParam.getColumnList());
        parameterObj.put(DataxConstants.ODPS_ACCESSID, dataxParam.getAccessId());
        parameterObj.put(DataxConstants.ODPS_ACCESSKEY, dataxParam.getAccessKey());
        parameterObj.put(DataxConstants.ODPS_TRUNCATE, dataxParam.getTruncate());
        parameterObj.put(DataxConstants.ODPS_SERVER, dataxParam.getOdpsServer());
        parameterObj.put(DataxConstants.ODPS_TUNNEL_SERVER, dataxParam.getTunnelServer());
        parameterObj.put(DataxConstants.ODPS_ACCOUNT_TYPE, dataxParam.getAccountType());

        writerObj.put(DataxConstants.PARAMETER, parameterObj);
        return writerObj;
    }

}
